package com.medplus.hubdirect.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;

@Entity
@Table(name="USER_ENDPOINT")
@NamedQueries({
@NamedQuery(
    name="findUserEndPointByName", query="SELECT p FROM UserEndPoint p where p.userName = :name and p.endPoint = :point")
})
public class UserEndPoint {

	private long sequence;
	
	@NotNull
	@Size(min=1, max=15)	
	private String endPoint;

	private String userName;
	private User user;
	
	private String message;
	
	@Id 
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "UserEndPointIdSeq")
	@SequenceGenerator(name="UserEndPointIdSeq",sequenceName="USER_ENDPOINT_ID_SEQ", allocationSize=1)
	@Column(name="USER_ENDPOINT_ID")
	public long getSequence() {
		return sequence;
	}
	public void setSequence(long sequence) {
		this.sequence = sequence;
	}
	
	@Column(name="USER_NAME")
	public String getUserName() {
		return userName;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}
	
	@Column(name="ENDPOINT")
	public String getEndPoint() {
		return endPoint;
	}
	public void setEndPoint(String endPoint) {
		this.endPoint = endPoint;
	}
	
	@ManyToOne
	@JoinColumn(name="USER_LIST_ID", referencedColumnName="USER_LIST_ID")
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
	
	
	/**
	 * @see java.lang.Object#equals(Object)
	 */
	public boolean equals(Object object) {
		if (!(object instanceof UserEndPoint)) {
			return false;
		}
		UserEndPoint rhs = (UserEndPoint) object;
		return new EqualsBuilder().appendSuper(super.equals(object)).append(
				this.endPoint, rhs.endPoint)
				.append(this.sequence, rhs.sequence)
				.isEquals();
	}
	
	/**
	 * @see java.lang.Object#hashCode()
	 */
	public int hashCode() {
		return new HashCodeBuilder(-509169145, -1960922129).appendSuper(
				super.hashCode()).append(this.endPoint).append(this.sequence)
				.toHashCode();
	}
	
	@Column(name="MESSAGE")
	@Lob
	public String getMessage() {
		return message;
	}
	public void setMessage(String message) {
		this.message = message;
	}
	
	
	
}
